package com.backstage.dao;

import com.backstage.pojo.Chatroom;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ChatroomMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Chatroom record);

    int insertSelective(Chatroom record);

    Chatroom selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Chatroom record);

    int updateByPrimaryKey(Chatroom record);

    @Select("select count(*) from chatroom_table")
    int selectChatroomTotal();

    /**
     * 查询用户“是否”能进入此聊天室
     * @param scopeId 区域ID
     * @param userId 用户ID
     * @param chatid 聊天室ID
     * @return
     */
    @Select("select * from chatroom_table where id=#{chatid} and (scopeid=#{scopeid} or userid=#{userid})")
    Chatroom selectChatroomHas(@Param("scopeid") Integer scopeId, @Param("userid") Integer userId, @Param("chatid") Integer chatid);

    @Select("select count(*) from chatroom_table where scopeid=#{id}")
    int selectChatroomScopeId(Integer id);

    @Select("select * from chatroom_table where scopeid=#{id} or userid=#{userid}")
    List<Chatroom> selectChatroomScopeIdList(@Param("id") Integer scopeId, @Param("userid") Integer userId);

    List<Chatroom> selectChatroomList(Chatroom record);
}